package models

import (
	"github.com/jinzhu/gorm"
)

type Cards struct {
	CardId         int            `gorm:"primary_key" json:"card_id"`
	Uid            string         `json:"uid"`
	CardCode       string         `json:"card_code"`
	CardNum        string         `json:"card_num"`
	CardExpired    int            `json:"card_expired"`
	CardType       string `json:"card_type"`
	CardFunc       string `json:"card_func"`
	CardDisabled   string `json:"card_disabled"`
	CardDesc       string `json:"card_desc"`
	CardScan       string `json:"card_scan"`
	ZoneId         int    `json:"zone_id"`
	BuildingId     int64  `json:"building_id"`
	UserId         int64  `json:"user_id"`
	RoomId         int64  `json:"room_id"`
	AgentAccountId int64  `json:"agent_account_id"`
	AccountId      int64  `json:"account_id"`
	LastUse        int64  `json:"last_use"`
	CardIsCpu      string `json:"card_is_cpu"`
	CardCpuSecret  string `json:"card_cpu_secret"`
	CreatedAt      int64  `json:"created_at"`
	UpdatedAt      int64  `json:"updated_at"`
	DeletedAt      int64  `json:"deleted_at"`
}



//后台门卡信息
func GetCardsInfo(code string) ([]*Cards, error) {
	var result []*Cards
	err:=db.Table("ims_cards").
		Where("card_code=? ",code).
		Find(&result).Error
	if err != nil && err != gorm.ErrRecordNotFound {
		return nil, err
	}
	//logging.Info(result)
	return result, nil
}


func UpdateCard(CardId int,secret string,okey string)(bool,error){
	result :=db.Table("ims_cards").Where("card_id = ?", CardId).Updates(map[string]interface{}{"card_cpu_secret": secret, "card_is_cpu": okey})
	if result.RowsAffected>0{
		return true,nil
	}else{
		return false,result.Error
	}
}